Skip to content

Resolve "batchOrder json does not support booleans"#390

Merged
btschwertfeger merged 1 commit into
btschwertfeger:masterfrom
claudeenriquez:fix/batchorder-json-encoding
Sep 1, 2025
Merged

Resolve "batchOrder json does not support booleans"#390
btschwertfeger merged 1 commit into
btschwertfeger:masterfrom
claudeenriquez:fix/batchorder-json-encoding

Conversation

@claudeenriquez
Copy link
Copy Markdown
Contributor

@claudeenriquez claudeenriquez commented Sep 1, 2025

Summary

Encode the batchOrder JSON object into a JSON text before passing it into the URL encoder, to support boolean values inside the object.

Changes / Features

Example:

from kraken.futures import Trade

client = Trade(
    key=",
    secret="",
    url="https://demo-futures.kraken.com"
)

response = client.create_batch_order(batchorder_list=[
    {
        "order": "send",
        "order_tag": "test",
        "orderType": "post",
        "symbol": "PF_XBTUSD",
        "side": "buy",
        "size": "1",
        "limitPrice": "1",
        "reduceOnly": True,
    }
])

print(response)

Before fix:

{'result': 'error', 'error': 'Json Parse Error', 'serverTime': '2025-09-01T06:25:42.751Z'}

After fix:

{'result': 'success', 'serverTime': '2025-09-01T06:24:11.557Z', 'batchStatus': [{'status': 'placed', 'order_tag': 'test', 'order_id': '9fc58abf-220a-44d8-91ce-d47493981538', 'dateTimeReceived': '2025-09-01T06:24:11.555Z', 'orderEvents': [{'type': 'PLACE', 'order': {'orderId': '9fc58abf-220a-44d8-91ce-d47493981538', 'cliOrdId': None, 'type': 'post', 'symbol': 'PF_XBTUSD', 'side': 'buy', 'quantity': 1, 'filled': 0, 'limitPrice': 1, 'reduceOnly': False, 'timestamp': '2025-09-01T06:24:11.555Z', 'lastUpdateTimestamp': '2025-09-01T06:24:11.555Z'}, 'reducedQuantity': None}]}]}

Closes #392

@btschwertfeger
Copy link
Copy Markdown
Owner

Hello @claudeenriquez, thanks a lot for the bugfix proposal! Could you please open an issue first that describes the problem and expected behavior? That’ll help us keep a clear record for the future.

@claudeenriquez
Copy link
Copy Markdown
Contributor Author

Hello @claudeenriquez, thanks a lot for the bugfix proposal! Could you please open an issue first that describes the problem and expected behavior? That’ll help us keep a clear record for the future.

Issue linked.

@btschwertfeger btschwertfeger added Bug Something isn't working Futures Topic related to Futures trading labels Sep 1, 2025
@btschwertfeger btschwertfeger added this to the Upcoming Release milestone Sep 1, 2025
Copy link
Copy Markdown
Owner

@btschwertfeger btschwertfeger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The proposed change looks absolutely legitimate and well-justified. Thanks for bringing it up! I double-checked your example, and it seems the required dumping comes from the boolean data type.

To make sure this works reliably now and going forward, could you please extend the unit test tests/futures/test_futures_trade.py::test_create_batch_order to include one order in the batchorderlist that sets "reduceOnly": True? That way we'll have full confidence the behavior stays correct in the future.

@claudeenriquez claudeenriquez force-pushed the fix/batchorder-json-encoding branch from 4967f06 to 622882a Compare September 1, 2025 13:43
@claudeenriquez
Copy link
Copy Markdown
Contributor Author

The proposed change looks absolutely legitimate and well-justified. Thanks for bringing it up! I double-checked your example, and it seems the required dumping comes from the boolean data type.

To make sure this works reliably now and going forward, could you please extend the unit test tests/futures/test_futures_trade.py::test_create_batch_order to include one order in the batchorderlist that sets "reduceOnly": True? That way we'll have full confidence the behavior stays correct in the future.

Done! Also ran pre-commit to pass the lint error.

@btschwertfeger btschwertfeger changed the title fix: batchOrder json does not support booleans Resolve "batchOrder json does not support booleans" Sep 1, 2025
@btschwertfeger btschwertfeger merged commit df2e812 into btschwertfeger:master Sep 1, 2025
30 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Something isn't working Futures Topic related to Futures trading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

batchOrder json does not support booleans

2 participants